package com.san.hkhospital.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.san.hkhospital.dto.Medbuy1;

import com.san.hkhospital.entity.MedBuy;
import com.san.hkhospital.service.MedBuyService;
import com.san.hkhospital.service.impl.MedBuyServiceImpl;
import com.san.hkhospital.vo.MedbuyVo;

import com.san.hkhospital.vo.ResultVO;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* (med_buy)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/med_buy")
public class MedBuyController {
/**
* 服务对象
*/
@Resource
private MedBuyServiceImpl medBuyServiceImpl;
@Resource
private MedBuyService medBuyService;
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("selectOne")
public MedBuy selectOne(Integer id) {
return medBuyServiceImpl.selectByPrimaryKey(id);
}

    //
    @RequestMapping("medbuyList")
    public ResultVO medbuyList(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<MedBuy> medBuyList = medBuyService.medbuyList();
        PageInfo<MedBuy> pageInfo = new PageInfo<MedBuy>(medBuyList);
        return ResultVO.success("药品采购记录已查询",pageInfo);
    }

    @RequestMapping("search")
    public ResultVO Search(@RequestBody Medbuy1 medbuy1,@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5") Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<MedbuyVo> medbuyList = medBuyService.search(medbuy1);
        PageInfo<MedbuyVo> pageInfo = new PageInfo<>(medbuyList);
        return ResultVO.success("查询完成", pageInfo);
    }



    @PostMapping
    public ResultVO buymedicine(@RequestBody MedBuy medBuy){
    boolean falg = medBuyService.buymedicine(medBuy);
    if(falg){
        return ResultVO.success("药品采购成功");
    }
    return ResultVO.failed("药品采购失败");
    }

}
